*---------- Cross section ------------------
gen t=tm(2010m1)+_n-1
format t %tm
tsset t
*replace sentiment=1.03e-06 if sentiment==. *-- replace missing values in sentiment w/ its average values 
* variable jumps is the categorical (0.1) of the rjv
* -------------------- Dynamic Markov Switching Model CDS----------------------

mswitch dr cds jumps, states(2) vce(robust) switch(L3.jumps) 
predict prjumps, pr
gen probabilities=prjumps*10
tsline probabilities cds

*mswitch dr cds sentiment, states(2) vce(robust) switch(L3.sentiment) 
*predict prsentiment, pr
*rename prsentiment s_probabilities 
*tsline s_probabilities cds

mswitch dr cds rcv, states(2) vce(robust) switch(L3.rcv) 
predict prrcv, pr
gen vola_probabilities=prrcv*10 
tsline vola_probabilities cds

* -------------------- Dynamic Markov Switching Model Equity----------------------
mswitch dr stock jumps_e, states(2) vce(robust) switch(L3.jumps_e) 
predict prjumps_e, pr
gen probabilities_e=prjumps_e*10
tsline probabilities_e stock

*mswitch dr cds sentiment, states(2) vce(robust) switch(L3.sentiment) 
*predict prsentiment, pr
*rename prsentiment s_probabilities 
*tsline s_probabilities cds

mswitch dr stock rcv_e, states(2) vce(robust) switch(L3.rcv_e) 
predict prrcv_e, pr
gen vola_probabilities_e=prrcv_e*10 
tsline vola_probabilities_e stock